<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class At_o_state extends CI_Controller {
	     public function __construct()
       {
            parent::__construct();
		$this->load->helper("html");
		$this->load->helper("url");
		$this->load->helper('form');
		$this->load->helper('date');
		$this->load->model("dv_model");
		$this->load->model("at_o_state_model");
		//$this->load->model("guest_comment_model");
		//$this->load->model("news_events_model");
		//$this->load->model("roomcottages_model");
		$this->load->helper(array('form', 'url'));
		$this->load->database();
	}
	//START ------------------at---------------------
	function index()
	{
	$data['title']="Administrator Page";
		$data["list_at_o_state"] = $this->at_o_state_model->get_all_at_o_state();	
		$this->load->view('at_o_state_list_view',$data);
	}
function ddlistsort()
	{
	$search=$_POST['search'];
	$data["search"]=$search;
	//$data["list_at"]=$this->at_model->get_at($search,false);
	$data["list_at_o_state"]=$this->at_o_state_model->get_at2($search);
	$this->load->view('at_o_state_list_view',$data);
  }

	function view_at_o_state()
	{
		$data['title']="Administrator Page";
		$code = $this->uri->segment(3);
		$data["list_at_o_state"] = $this->at_o_state_model->getat_o_state_info($code);
		//$data["list_customers"] = $this->customers_model->getcustomers();
		$this->load->view('at_o_state_list_view',$data);
	}

	function add_at_o_state()
	{
		$data['title']="Administrator Page";
		$code = $this->uri->segment(3);
		$data["list_at_o_state"] = $this->at_o_state_model->getat_o_state_info($code);		
		$this->load->view('at_o_state_add_view',$data);
	}

	function p_getinfo()
	{		
		$info = $this->dv_model->getatInfoby_dv_company_name($_GET['dv_company_name']);			
		$this->output->set_content_type('application/json');
    	$this->output->set_output(json_encode($info));
	}

	function p_add_at_o_state()
	{
		$this->load->database();			
		$load_no =$_POST['txtload_no'];
		$f_name =$_POST['txtf_name'];
		$dv_company_name =$_POST['dv_company_name'];
		$drop_off_city =$_POST['txtdrop_off_city'];
		$drop_off_state =$_POST['txtdrop_off_state'];
		$drop_off_date =$_POST['txtdrop_off_date'];
		$type_of_truck=$_POST['txttype_of_truck'];
		$mc_num =$_POST['txtmc_num'];
		$des_city =$_POST['txtdes_city'];
		$des_state =$_POST['txtdes_state'];
		$des_zone =$_POST['txtdes_zone'];		
		$note =$_POST['note'];		
		
		$loadinfo = $this->at_o_state_model->getat_o_stateInfoByLoadNo($load_no,$f_name,$dv_company_name,$drop_off_city,$drop_off_state,$drop_off_date,$type_of_truck,$mc_num,$des_city,$des_state,$des_zone);
		if($loadinfo==null){							 
			$_sql="insert into available_truck (load_no,f_name,dv_company_name,drop_off_city,drop_off_state,drop_off_date,type_of_truck,mc_num,des_city,des_state,des_zone,note)";
			$_sql.="values('$load_no','$f_name','$dv_company_name','$drop_off_city','$drop_off_state','$drop_off_date','$type_of_truck','$mc_num','$des_city','$des_state','$des_zone','$note')";
			$query = $this->db->query($_sql); 		
			$data["list_at_o_state"] = $this->at_o_state_model->get_all_at_o_state();	
			$this->load->view('at_o_state_list_view',$data);
		}
		else{			
			$data["data_exist"] = "[$load_no] - Load No. already exist.";	
			$this->load->view('at_add_view',$data);		
		}	
	}

	function edit_at_o_state()
	{
 	    $code = $this->uri->segment(3);
		$data["info"] = $this->at_o_state_model->getat_o_state_info($code);	
		$this->load->view('at_o_state_edit_view',$data);
	}
	function p_edit_at()
	{
		$this->load->database();
		$at_id =$_POST['hid_atid'];
		$load_no =$_POST['txtload_no'];
		$f_name =$_POST['txtf_name'];
		$dv_company_name =$_POST['dv_company_name'];
		$drop_off_city =$_POST['txtdrop_off_city'];
		$drop_off_state =$_POST['txtdrop_off_state'];
		$drop_off_date =$_POST['txtdrop_off_date'];
		$type_of_truck=$_POST['txttype_of_truck'];
		$mc_num =$_POST['txtmc_num'];
		$des_city =$_POST['txtdes_city'];
		$des_state =$_POST['txtdes_state'];
		$des_zone =$_POST['txtdes_zone'];		
		$note =$_POST['note'];		
		//$select =$_POST['select'];				
			$query = $this->db->query("UPDATE available_truck SET      load_no='$load_no',
														  f_name='$f_name',
														  dv_company_name='$dv_company_name',
														  drop_off_city='$drop_off_city',
														  drop_off_state='$drop_off_state',														
														  drop_off_date='$drop_off_date',
														  type_of_truck='$type_of_truck',	
														  mc_num='$mc_num',															  
														  des_city='$des_city',
														  des_state='$des_state',
														  des_zone='$des_zone',
														  note='$note' where at_id= $at_id"); 		
		$data["list_at_o_state"] = $this->at_o_state_model->get_all_at_o_state();	
		$this->load->view('at_o_state_list_view',$data);		
	}

	function delete_at_o_state()
	{
		$this->load->database();		
		$code = $this->uri->segment(3);
		$query = $this->db->query("delete from available_truck where at_id='$code'");
		$data["list_at_o_state"] = $this->at_o_state_model->get_all_at_o_state();	
		$this->load->view('at_o_state_list_view',$data);
	}
	//END ------------------at---------------------
	function logout()

	{
		//$this->load->library('session');
		//$this->session->sess_destroy();
		session_start();
		session_destroy();
		//echo $_SESSION['Administrator_log'];
	//unset($_SESSION['Administrator_log']);
			//$data["newsresult"] = $this->at_model->dv_all_driver_vendor();
			$this->load->view('admin_view');
		}
}

?>